package hn.cch.spring.aop.aspect.demo;

import hn.cch.spring.aop.MethodInvocationImpl;
import hn.cch.spring.aop.aspect.ExecutionTarget;
import hn.cch.spring.aop.aspect.MethodInterceptorImpl;
import hn.cch.spring.aop.aspect.MethodInterceptorImpl0;
import hn.cch.spring.aop.aspect.MethodInterceptorImpl1;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;

public class MethodInvocationDemo {

    public static void main(String[] args) throws Throwable {
         // 责任链模式：递归调用
         ExecutionTarget executionTarget = new ExecutionTarget();
        Method method = ExecutionTarget.class.getMethod("around", String.class);

        List<MethodInterceptor> methodInterceptorList = Arrays.asList(new MethodInterceptorImpl(), new MethodInterceptorImpl0(), new MethodInterceptorImpl1());
        MethodInvocation methodInvocation = new MethodInvocationImpl(executionTarget, method, new Object[]{"xyz"}, methodInterceptorList);
        methodInvocation.proceed();
    }
}
